use clap::Parser;
use ctapi::argument::{Argument, GenerateCommand};
use ctapi::config::Config;
use ctapi::util::Util;
use ctapi::{
    custom_filter, generate_config, generate_device_list, generate_update_setting, router, run,
};
use snafu::ResultExt;
use std::io::{stderr, stdout};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use tokio::signal::{self, ctrl_c};
use tokio::sync::oneshot;
use tracing::{Level, debug, info};
use tracing_subscriber::fmt::writer::MakeWriterExt;
use warp::{Filter, Reply};

#[tokio::main]
async fn main() {
    let argument = Argument::parse();

    match argument.take_command() {
        ctapi::argument::Command::Run(run_argument) => run(run_argument).await,
        ctapi::argument::Command::Generate { command } => match command {
            GenerateCommand::UpdateSetting { save } => {
                generate_update_setting(save).await;
            }
            GenerateCommand::Config { save } => {
                generate_config(save).await;
            }
            GenerateCommand::DeviceList { save } => {
                generate_device_list(save).await;
            }
        },
    }
}
